var commonopinionid;

$(function(){

	commonopinionid = getUrlParam('commonopinionid');
	initForm(commonopinionid);
})

function initForm(commonopinionid){

	var infoUrl = projectPath + "sys/getcommonopinioninfo.do";
	
	$.ajax({ 
		url: infoUrl,
		data: {"commonopinionid": commonopinionid},
		dataType: "json",
		success: function(data){
			if(data.result == 1){   
				bindFormInfo(data.datas);
			}
      	}
	});
}

function bindFormInfo(data){
	$('[name="opinion"]').val(data.opinion);
	$('[name="count"]').val(data.count);
}




function save(){
	var saveData = $("#dataForm").serializeObject();
	saveData['commonopinionid'] = commonopinionid;


	if(!check(saveData))
		return true;
	
	$.ajax({ 
		method: 'post',
		url: basePath() + 'sys/updatecommonopinion.do',
		data: JSON.stringify(saveData),
		dataType: "json",
        contentType: "application/json",
		success: function(data){	
	    	window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.success, {
	    		onOk: function(){
	    			if(data.result == 1){
	    				parent.refreshData();		//刷新数据
	    			} 
	    		}
	    	});
      	}
	});
}

function check(data){	
	var result = true;
	

	var mustStr = "opinion,count";
	
	var strMsg = "";
	var mustStrs = mustStr.split(',');
	for(var i=0; i<mustStrs.length; i++){
		var obj = $('[name="'+mustStrs[i]+'"]');
		if(obj.val() == ""){
			strMsg += obj.attr("placeholder") + "！<br />";
			
			result = false;
		}
	}
	

	
	
	if(strMsg != ""){
		window.wxc.xcConfirm(strMsg, window.wxc.xcConfirm.typeEnum.error);
	}
	
	return result;
}
